using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
	
    public class GadgetInfo
    {
		#region Local Variable
		public enum Field
		{
			ID,
			Title,
			Width,
			Height,
			Image,
			Type
		}
		private Int32 _ID;
		private String _Title;
		private Int32 _Width;
		private Int32 _Height;
		private String _Image;
		private String _Type;
		
		public Int32 ID{	get{ return _ID;} set{_ID = value;} }
		public String Title{	get{ return _Title;} set{_Title = value;} }
		public Int32 Width{	get{ return _Width;} set{_Width = value;} }
		public Int32 Height{	get{ return _Height;} set{_Height = value;} }
		public String Image{	get{ return _Image;} set{_Image = value;} }
		public String Type{	get{ return _Type;} set{_Type = value;} }
		
        #endregion LocalVariable
        
        #region Constructor
		public GadgetInfo()
		{
			_ID = 0;
			_Title = "";
			_Width = 0;
			_Height = 0;
			_Image = "";
			_Type = "";
		}
		public GadgetInfo(
		Int32 ID,
		String Title,
		Int32 Width,
		Int32 Height,
		String Image,
		String Type
		)
		{
			_ID = ID;
			_Title = Title;
			_Width = Width;
			_Height = Height;
			_Image = Image;
			_Type = Type;
		}
		public GadgetInfo(DataRow dr)
		{
			if (dr != null)
			{
				_ID = dr[Field.ID.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.ID.ToString()]);
				_Title = dr[Field.Title.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Title.ToString()]);
				_Width = dr[Field.Width.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.Width.ToString()]);
				_Height = dr[Field.Height.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.Height.ToString()]);
				_Image = dr[Field.Image.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Image.ToString()]);
				_Type = dr[Field.Type.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Type.ToString()]);
			}
		}
		public GadgetInfo(GadgetInfo objEntr)
		{			
			_ID = objEntr.ID;			
			_Title = objEntr.Title;			
			_Width = objEntr.Width;			
			_Height = objEntr.Height;			
			_Image = objEntr.Image;			
			_Type = objEntr.Type;			
		}
        #endregion Constructor
        
        #region InitTable
		public DataTable ToDataTable()
		{
			DataTable dt = new DataTable("Gadget");
			dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.ID.ToString(), typeof(Int32)),
				new DataColumn(Field.Title.ToString(), typeof(String)),
				new DataColumn(Field.Width.ToString(), typeof(Int32)),
				new DataColumn(Field.Height.ToString(), typeof(Int32)),
				new DataColumn(Field.Image.ToString(), typeof(String)),
				new DataColumn(Field.Type.ToString(), typeof(String))
			});
			return dt;
		}
		public DataRow ToDataRow(DataTable dt)
		{
			DataRow row = dt.NewRow();
			row[Field.ID.ToString()] = _ID;
			row[Field.Title.ToString()] = _Title;
			row[Field.Width.ToString()] = _Width;
			row[Field.Height.ToString()] = _Height;
			row[Field.Image.ToString()] = _Image;
			row[Field.Type.ToString()] = _Type;
			return row;
		}
        #endregion InitTable
    }
}
